package cn.rengy.web.framework.wxmp.component.token;

import cn.rengy.tpa.wxmp.exception.WeChatException;
import cn.rengy.tpa.wxmp.token.AccessToken;
/**
 * 第三方平台的接口调用令牌，有效期2小时
 * @author rengy
 *
 */
public class ComponentAccessTokenImpl implements AccessToken {

	private String accessToken;
	private ComponentTokenService componentTokenService;
	private String component_app_id;
	
	public ComponentAccessTokenImpl(ComponentTokenService componentTokenService,String component_app_id){
		this.componentTokenService=componentTokenService;
		this.component_app_id=component_app_id;
	}
	@Override
	public String token() throws WeChatException {
		accessToken=componentTokenService.accessToken(component_app_id);
		return accessToken;
	}

	@Override
	public void refresh() throws WeChatException {
		componentTokenService.evictAccessToken(component_app_id, accessToken);
	}

}
